package com.mlt.back.dao.impl;

import com.mlt.back.dao.Manager_RoleDao;
import com.mlt.back.utils.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Manager_RoleDaoImpl implements Manager_RoleDao {
    @Override
    public int insert(String mgr_id, String role_id) {
        int count=0;
        Connection conn=null;
        PreparedStatement ps=null;
        try {
            conn= DBUtil.getConnection();
            String sql="insert into t_mgr_role(mgr_id,role_id) values(?,?)";
            ps=conn.prepareStatement(sql);
            ps.setString(1,mgr_id);
            ps.setString(2,role_id);
            count=ps.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DBUtil.close(null,ps,null);
        }
        return count;
    }

    @Override
    public void update(String mgr_id, String role_id) {
        Connection conn=null;
        PreparedStatement ps=null;
        try {
            conn= DBUtil.getConnection();
            String sql="update t_mgr_role set role_id=? where mgr_id=?";
            ps=conn.prepareStatement(sql);
            ps.setString(1,role_id);
            ps.setString(2,mgr_id);
            ps.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DBUtil.close(conn,ps,null);
        }
    }
}
